# !/usr/bin python3
# encoding: utf-8 -*-
# @file     : ws_client.py
# @author   : 沙陌 Matongxue_2
# @Time     : 2023/8/10 20:26
# @Copyright: 北京码同学
from common.file_load import load_yaml_file
from common.logger import GetLogger
from paths_manager import websocket_yaml


class WebSocketClient:

    def __init__(self):
        self.host = load_yaml_file(websocket_yaml)['host']

    def send(self, params):
        try:
            self.ws.send(params)
            GetLogger.get_logger().info(f'消息发送成功:{params}')
        except:
            GetLogger.get_logger().exception(f'消息发送失败')
            raise BaseException('消息发送失败')

    def recv(self):
        try:
            result = self.ws.recv()
            GetLogger.get_logger().info(f'接收消息成功:{result}')
            return result
        except:
            GetLogger.get_logger().exception(f'接收消息失败')
            raise BaseException('接收消息失败')
